package com.jmb.controller;

import com.jmb.po.UserInformation;
import com.jmb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserService userService;
//name和value的区别
    @RequestMapping(value = "/getByTel" , method = RequestMethod.GET)
    public UserInformation findByTel(String tel){
        return userService.findByTel(tel);
    }

    @RequestMapping(value = "/getById" , method = RequestMethod.GET)
    public UserInformation findById(int id){
        return userService.findById(id);
    }

    @RequestMapping(value = "/all" , method = RequestMethod.GET)
    public List<UserInformation> findAll(){
        return userService.findAll();
    }

    @RequestMapping(value = "/up" , method = RequestMethod.PUT)
    public boolean update(@RequestBody UserInformation user){
        return userService.updateUser(user);
    }

    @RequestMapping(value = "/add" , method = RequestMethod.POST)
    public boolean add(@RequestBody UserInformation user){

        return userService.addUser(user);
    }

    @RequestMapping(value = "/del" , method = RequestMethod.DELETE)
    public boolean del(String tel){
        return userService.delUser(tel);
    }
}
